package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.SchoolQuarter;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 每个学期存在的校区 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-09-28
 */
public interface SchoolQuarterMapper extends BaseMapper<SchoolQuarter> {

    @Select("select GROUP_CONCAT(school_id) as school_ids from school_quarter where year_part = ${yearPart} and quarter_num = ${quarterNum} and deleted = 0 and (school_id in(${schoolId}) or pid in( ${schoolId}))")
    public String getChilIds(@Param("yearPart") Integer yearPart,@Param("quarterNum") Integer quarterNum, @Param("schoolId") String schoolId);

    @Select("select school_id from school_quarter where year_part = ${yearPart} and quarter_num = ${quarterNum} and deleted = 0 and (school_id in(${schoolId}) or pid in( ${schoolId}))")
    public List<Long> getChilIdList(@Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("schoolId") String schoolId);

    @Select("SELECT GROUP_CONCAT(school_id) AS school_id FROM school_quarter AS sq WHERE ( sq.school_id IN ( SELECT DISTINCT pid FROM school_quarter WHERE school_id IN (${schoolId}) AND year_part = ${yearPart} AND quarter_num = ${quarterNum} ) OR sq.school_id IN (${schoolId}) ) AND sq.year_part = 2024 AND sq.quarter_num = 4 AND pid = 0 AND sq.deleted = 0")
    public String getBigSchoolIdStr(@Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("schoolId") String schoolId);

    @Select("select school_id from school_quarter where year_part = ${yearPart} and quarter_num = ${quarterNum} and deleted = 0")
    public List<Long> getSchoolIdList(@Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum);

    @Select("select GROUP_CONCAT(school_id) as school_id from school_quarter where year_part = ${yearPart} and quarter_num = ${quarterNum} and deleted = 0")
    public String getSchoolIdStr(@Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum);

}
